<?php

class ListingsTemplate{
	public static function getEditForm($term){

		$water = get_metadata('listing_term', $term->term_id, 'base_line_water',true);
		$energy = get_metadata('listing_term', $term->term_id, 'base_line_energy',true);

		?>
			<tr class="form-field">
				<th scope="row"><label for="base_line_water">Línea Base de Agua (S/.):</label></th>
				<td><input name="base_line_water" id="base_line_water" type="text" value="<?php echo $water;?>" size="40" aria-required="true"></td>
				
								
			</tr>
			<tr class="form-field">
				<th scope="row"><label for="base_line_energy">Línea Base de Energía (S/.):</label></th>
				<td><input name="base_line_energy" id="base_line_energy" type="text" value="<?php echo $energy;?>" size="40" aria-required="true"></td>
				
								
			</tr>
		<?php
		
			
		
	}
	public static function getCreateForm(){
		?>
		<div class="form-field">
				<label for="base_line_water">Línea Base de Agua (S/.):</label>
				<input name="base_line_water" id="base_line_water" type="text" value="" size="40" aria-required="true">
				<p class="description">Línea Base que se usará en este rubro</p>
		</div>
		<div class="form-field">
				<label for="base_line_energy">Línea Base de Energía (S/.):</label>
				<input name="base_line_energy" id="base_line_energy" type="text" value="" size="40" aria-required="true">
				<p class="description">Línea Base que se usará en este rubro</p>
		</div>

		<?php
	}


	public static function saveCreateEditForm($term_id){
		if (isset($_POST['base_line_water'])) {
            $base_line_water = esc_attr($_POST['base_line_water']);
            $water = get_metadata('listing_term', $term->term_id, 'base_line_water',true);
			if($water){
				add_metadata('listing_term', $term_id, 'base_line_water', $base_line_water,true); 	
			}else{
           		update_metadata('listing_term', $term_id, 'base_line_water', $base_line_water);
           	}
        }
       
		
        if (isset($_POST['base_line_energy'])) {
            $base_line_energy = esc_attr($_POST['base_line_energy']);
            $energy = get_metadata('listing_term', $term->term_id, 'base_line_energy',true);
            if($energy){
				add_metadata('listing_term', $term_id, 'base_line_energy', $base_line_energy,true); 
			}else{
				update_metadata('listing_term', $term_id, 'base_line_energy', $base_line_energy);

           	}
           
        }
	}
}

?>